<template>
  <el-dialog :visible.sync="modals" :title="$t('faSongHuo')" class="order_box" :before-close="handleClose" width="600px">
    <el-form ref="formItem" :model="formItem" label-width="110px" :rules="rules" @submit.native.prevent>
      <el-form-item :label="$t('kuaiDiGongSi')+'：'" prop="expressCode">
        <el-select v-model="formItem.deliveryId" filterable style="width: 80%">
          <el-option
            v-for="(item, i) in express"
            :key="i"
            :value="item.deliveryId"
            :label="item.deliveryName"
          />
        </el-select>
      </el-form-item>
      <el-form-item :label="$t('kuaiDiDanHao')+'：'" prop="waybillId">
        <el-input v-model="formItem.waybillId" :placeholder="$t('qingShuRuKuaiDiDanHao')" style="width: 80%" />
      </el-form-item>
    </el-form>
    <div slot="footer">
      <el-button
        v-hasPermi="['admin:order:video:send']"
        size="mini"
        type="primary"
        @click="putSend('formItem')"
      >{{ $t('confirm') }}</el-button>
      <el-button size="mini" @click="cancel('formItem')">{{ $t('cancel') }}</el-button>
    </div>
  </el-dialog>
</template>

<script>
import { videoSendApi, sheetInfoApi, companyGetListApi } from '@/api/order'
import { Debounce } from '@/utils/validate'

export default {
  name: 'OrderSend',
  props: {
    orderId: String
  },
  data() {
    return {
      formItem: {
        deliveryId: '',
        orderNo: '',
        waybillId: ''
      },
      modals: false,
      express: [],
      exportTempList: [],
      tempImg: '',
      rules: {
        deliveryId: [{ required: true, message: this.$t('qingXuanZeKuaiDiGongSi'), trigger: 'change' }],
        waybillId: [{ required: true, message: this.$t('qingShuRuKuaiDiDanHao'), trigger: 'blur' }]
      },
      expressType: 'normal'
    }
  },
  mounted() {
    this.express = JSON.parse(sessionStorage.getItem('videoExpress'))
  },
  methods: {
    // 视频号快递公司
    companyGetList() {
      companyGetListApi().then(async(res) => {
        this.express = res
        sessionStorage.setItem('videoExpress', JSON.stringify(res))
      })
    },
    // 提交
    putSend: Debounce(function(name) {
      this.formItem.orderNo = this.orderId
      this.$refs[name].validate((valid) => {
        if (valid) {
          videoSendApi(this.formItem).then((async) => {
            this.$message.success(this.$t('faSongHuoChengGong'))
            this.modals = false
            this.$refs[name].resetFields()
            this.$emit('submitFail')
          })
        } else {
          this.$message.error(this.$t('qingTianXieXinXi'))
        }
      })
    }),
    handleClose() {
      this.cancel('formItem')
    },
    cancel(name) {
      this.modals = false
      this.$refs[name].resetFields()
      this.formItem.type = '1'
      this.formItem.expressRecordType = '1'
    }
  }
}
</script>

<style scoped lang="scss">
.width8 {
  width: 80%;
}

.width9 {
  width: 70%;
}

.tempImgList {
  // opacity: 1;
  width: 38px !important;
  height: 30px !important;
  // margin-top: -30px;
  cursor: pointer;
  position: absolute;
  z-index: 11;
  img {
    width: 38px !important;
    height: 30px !important;
  }
}
</style>
